package concurrent;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

/**
 * User: Administrator
 * Date: 2021/2/19
 * Time: 14:09
 * Description:
 */
public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> completableFuture = new CompletableFuture<>();
        boolean b = completableFuture.complete("完成");

        CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> {
            System.out.println("无返回值，异步任务");
        });

        CompletableFuture<Object> future2 = CompletableFuture.supplyAsync(new Supplier<Object>() {
            @Override
            public Object get() {
                return "有返回值，异步任务";
            }
        });

        Object o = future2.get();
        System.out.println(o);
    }
}
